
//#include <windows.h>
#include <ukapi.h>
#include <kernel.h>

extern void OEMWriteDebugByte( unsigned char c );

//ROMHDR * volatile const pTOC = (ROMHDR *)-1; 
unsigned long * volatile const pTOC = (unsigned long *)-1; 


/*
  	@func   void    |   OEMWriteDebugString | Display string to the monitor port. 
  	@parm   unsigned short * | str |   Points to the receiving buffer.
    @rdesc   N/A.   	
    @comm    Never return from here
    @xref   	
*/
void OEMWriteDebugString(unsigned char *str) 
{
	// Loop through text string, sending characters.
	//
  while (str && *str)
	{
        OEMWriteDebugByte((unsigned char)*str++);
	}
}

void output( string_ascii_t msg )
{
	OEMWriteDebugString( (unsigned char *) msg );
}

char_ascii_t input()
{
	return (char_ascii_t) OEMReadDebugByte();
}


#define system_interrupt_timer		system_interrupt_device + 1

interrupt_t irq_timer; // ??

/***

In IT Handler : 

interrupt_manager_handle_interrupt( &g_kernel.interrupt_manager, &irq_timer );

***/


void _main(void)
{
		result_t res;
		
		output( "\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" );
	
		debug_zone_add( debug_zone_info_e, info_zone_ukapi_funtion_entry_e );
		debug_zone_add( debug_zone_info_e, info_zone_ukapi_funtion_return_e );
		debug_zone_add( debug_zone_info_e, info_zone_funtion_entry_e );
		debug_zone_add( debug_zone_info_e, info_zone_funtion_return_e );
		
		debug_on();
	
		res = kernel_init( input, output, true, 0 );
		
	
		if ( result_failed( res ) )
		{
			output( "kernel_init failed\n" );
			return;
		}	
		
		debug_zone_add( debug_zone_info_e, info_zone_unknown );
	
		interrupt_create( &irq_timer, system_interrupt_scheduler );

	
	  // Should never get here
		while ( 1 )
		{
			Sleep( 1000 );
		}
			
		return;
}
